﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Log;

namespace UtilZ.Dotnet.Ex.Communication.Net.Ftp
{
    /// <summary>
    /// ftp状态码
    /// </summary>
    public class FtpStatusCodes
    {
        private static readonly IReadOnlyDictionary<short, string> _codeNameDic;
        static FtpStatusCodes()
        {
            _codeNameDic = new Dictionary<short, string>()
            {
                { Code110,"Restart marker reply"},
                { Code120,"Service ready in nnn minutes"},
                { Code125,"Data connection already open; transfer starting"},
                { Code150,"File status okay; about to open data connection"},
                { Code200,"Command okay"},

                { Code202,"Command not implemented, superfluous at this site"},
                { Code211,"System status, or system help reply"},
                { Code212,"Directory status"},
                { Code213,"File status"},
                { Code214,"Help message"},

                { Code215,"NAME system type"},
                { Code220,"Service ready for new user"},
                { Code221,"Service closing control connection"},
                { Code225,"Data connection open; no transfer in progress"},
                { Code226,"Closing data connection"},

                { Code227,"Entering Passive Mode (h1,h2,h3,h4,p1,p2)"},
                { Code230,"User logged in, proceed"},
                { Code250,"Requested file action okay, completed"},
                { Code257,"\"PATHNAME\" created"},
                { Code331,"User name okay, need password"},

                { Code332,"Need account for login"},
                { Code350,"Requested file action pending further information"},
                { Code421,"Service not available, closing control connection"},
                { Code425,"Can't open data connection"},
                { Code426,"Connection closed; transfer aborted"},

                { Code450,"Requested file action not taken"},
                { Code451,"Requested action aborted. Local error in processing"},
                { Code452,"Requested action not taken"},
                { Code500,"Requested action not taken"},
                { Code501,"Syntax error in parameters or arguments"},

                { Code502,"Command not implemented"},
                { Code503,"Bad sequence of commands"},
                { Code504,"Command not implemented for that parameter"},
                { Code530,"Not logged in"},
                { Code532,"Need account for storing files"},

                { Code534,"Local policy on server does not allow TLS secure connections"},
                { Code550,"Requested action not taken"},
                { Code551,"Requested action aborted. Page type unknown"},
                { Code552,"Requested file action aborted"},
                { Code553,"Requested action not taken"},
            };
        }

        /// <summary>
        /// 根据值获取名称
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>名称</returns>
        public static string GetNameByValue(short value)
        {
            if(_codeNameDic.TryGetValue(value,out var name))
            {
                return name;
            }
            
            return $"unknown code {value}";
        }






        /// <summary>
        /// 重新开始标记响应.
        /// 对于这种情况，文本应该是明确的，无需进行特殊实现；必须形如：MARK yyyy = mmmm；yyyy 是用户进程数据流标记，mmmm服务器的等效标记（注意，标记间的空格和“=“）
        /// Restart marker reply
        /// </summary>
        public const short Code110 = 110;

        /// <summary>
        /// 服务器准备就绪的时间（分钟数）,服务将在nnn分钟后准备完成
        /// Service ready in nnn minutes
        /// </summary>
        public const short Code120 = 120;

        /// <summary>
        /// 数据连接已打开，传输开始,
        /// Data connection already open; transfer starting.
        /// </summary>
        public const short Code125 = 125;

        /// <summary>
        /// 文件状态 OK，将打开数据连接
        /// File status okay; about to open data connection
        /// </summary>
        public const short Code150 = 150;





        /// <summary>
        /// 命令成功
        /// Command okay
        /// </summary>
        public const short Code200 = 200;

        /// <summary>
        /// 命令没有实现，对本站点冗余
        /// Command not implemented, superfluous at this site
        /// </summary>
        public const short Code202 = 202;

        /// <summary>
        /// 系统状态，或者系统帮助响应
        /// System status, or system help reply
        /// </summary>
        public const short Code211 = 211;

        /// <summary>
        /// 目录状态
        /// Directory status
        /// </summary>
        public const short Code212 = 212;

        /// <summary>
        /// 文件状态
        /// File status
        /// </summary>
        public const short Code213 = 213;

        /// <summary>
        /// （帮助信息）关于如何如使用服务器，或者特殊的非标准的命令的意义。只对人类用户有用
        /// Help message
        /// </summary>
        public const short Code214 = 214;

        /// <summary>
        /// （系统类型名称）这里的 NAME 指在 Assigned Numbers 文档中列出的正式名称
        /// NAME system type
        /// </summary>
        public const short Code215 = 215;

        /// <summary>
        /// 接受新用户服务准备完成
        /// Service ready for new user
        /// </summary>
        public const short Code220 = 220;

        /// <summary>
        /// （服务关闭控制连接）已注消
        /// Service closing control connection
        /// </summary>
        public const short Code221 = 221;

        /// <summary>
        /// （数据连接打开，没有传输）
        /// Data connection open; no transfer in progress
        /// </summary>
        public const short Code225 = 225;

        /// <summary>
        /// （关闭数据连接）请求文件动作成功（例如，文件传输或者放弃）
        /// Closing data connection
        /// </summary>
        public const short Code226 = 226;

        /// <summary>
        /// 进入被动模式（IP 地址、ID 端口）
        /// Entering Passive Mode (h1,h2,h3,h4,p1,p2)
        /// </summary>
        public const short Code227 = 227;

        /// <summary>
        /// (用户成功登录，继续）
        /// User logged in, proceed
        /// </summary>
        public const short Code230 = 230;

        /// <summary>
        /// （请求文件动作 OK，完成）
        /// Requested file action okay, completed
        /// </summary>
        public const short Code250 = 250;

        /// <summary>
        /// 创建路径完成
        /// "PATHNAME" created
        /// </summary>
        public const short Code257 = 257;





        /// <summary>
        /// （用户名 OK，需要密码）
        /// User name okay, need password
        /// </summary>
        public const short Code331 = 331;

        /// <summary>
        /// 需要帐户才能登录
        /// Need account for login
        /// </summary>
        public const short Code332 = 332;

        /// <summary>
        /// 请求文件动作需要进一步的信息
        /// Requested file action pending further information
        /// </summary>
        public const short Code350 = 350;






        /// <summary>
        /// （服务不可用，关闭控制连接）如果服务器知道它必须关闭，应该以 421 作为任何命令的响应代码。
        /// Service not available, closing control connection
        /// </summary>
        public const short Code421 = 421;

        /// <summary>
        /// 不能打开数据连接
        /// Can't open data connection
        /// </summary>
        public const short Code425 = 425;

        /// <summary>
        /// 连接关闭，放弃传输
        /// Connection closed; transfer aborted
        /// </summary>
        public const short Code426 = 426;

        /// <summary>
        /// （请求文件动作没有执行）文件不可使用（例如，文件忙）
        /// Requested file action not taken
        /// </summary>
        public const short Code450 = 450;

        /// <summary>
        /// 请求动作放弃，处理中发生本地错误
        /// Requested action aborted. Local error in processing
        /// </summary>
        public const short Code451 = 451;

        /// <summary>
        /// （请求动作未执行）系统存储空间不足
        /// Requested action not taken
        /// </summary>
        public const short Code452 = 452;





        /// <summary>
        /// (请求的动作没有执行）文件不可用（例如，没有找到文件，没有访问权限）
        /// Requested action not taken
        /// </summary>
        public const short Code500 = 500;

        /// <summary>
        /// 参数语法错误
        /// Syntax error in parameters or arguments
        /// </summary>
        public const short Code501 = 501;

        /// <summary>
        /// 命令没有实现
        /// Command not implemented
        /// </summary>
        public const short Code502 = 502;

        /// <summary>
        /// 命令顺序错误
        /// Bad sequence of commands
        /// </summary>
        public const short Code503 = 503;

        /// <summary>
        /// 没有实现这个命令参数
        /// Command not implemented for that parameter
        /// </summary>
        public const short Code504 = 504;

        /// <summary>
        /// 未登录
        /// Not logged in
        /// </summary>
        public const short Code530 = 530;

        /// <summary>
        /// 需要帐户来存储文件
        /// Need account for storing files
        /// </summary>
        public const short Code532 = 532;

        /// <summary>
        /// 不支持安全连接
        /// Local policy on server does not allow TLS secure connections
        /// </summary>
        public const short Code534 = 534;

        /// <summary>
        /// (请求的动作没有执行）文件不可用（例如，没有找到文件，没有访问权限）
        /// Requested action not taken
        /// </summary>
        public const short Code550 = 550;

        /// <summary>
        /// （请求动作放弃，未知的页面类型）
        /// Requested action aborted. Page type unknown
        /// </summary>
        public const short Code551 = 551;

        /// <summary>
        /// (请求文件动作被放弃)超出存储分配空间（当前的路径或者数据集）
        /// Requested file action aborted
        /// </summary>
        public const short Code552 = 552;

        /// <summary>
        /// （请求动作未获得）文件名不允许
        /// Requested action not taken
        /// </summary>
        public const short Code553 = 553;

    }
}


